/**
 * 
 */
package com.skymobi.hellophonegap;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 绫诲悕绉� DialogEx
 * <p>浣滆�:  kabing.rao
 * <p>鍒涘缓鏃堕棿: 2012-3-13
 * <p>绫绘弿杩� 
 * <p>鐗堟潈澹版槑 : Copyright (C) 2008-2011 鏉窞鏂嚡缃戠粶绉戞妧鏈夐檺鍏徃(SKY-MOBI CO.,LTD)
 * <p>淇敼鏃堕棿:  
 * 
 */
public class DialogEx extends Dialog {
    
    public final static int SINGLE_BUTTON_DIALOG=1;
    public final static int DOUBLE_BUTTON_DIALOG=2;
    public final static int INPUT_DIALOG=4;
    
//    private int mType;


    public DialogEx(Context context, int theme) {
        super(context, R.style.dialog);
        // TODO Auto-generated constructor stub
        setContentView(R.layout.dialog);
    }
    
    public void setDialogType(int type){
//        mType = type;
        if(type==SINGLE_BUTTON_DIALOG){
            TextView txtTitle = (TextView)findViewById(R.id.txt_dialog_content);
            txtTitle.setVisibility(View.VISIBLE);
            LinearLayout layout = (LinearLayout)findViewById(R.id.dialog_single_btn_layout);
            layout.setVisibility(View.VISIBLE);
        }else if(type==DOUBLE_BUTTON_DIALOG){
            TextView txtTitle = (TextView)findViewById(R.id.txt_dialog_content);
            txtTitle.setVisibility(View.VISIBLE);
            LinearLayout layout = (LinearLayout)findViewById(R.id.dialog_two_btn_layout);
            layout.setVisibility(View.VISIBLE);
        }else if(type==INPUT_DIALOG){
            LinearLayout layout1 =  (LinearLayout)findViewById(R.id.dialog_input_layout);
            layout1.setVisibility(View.VISIBLE);
            LinearLayout layout2 = (LinearLayout)findViewById(R.id.dialog_two_btn_layout);
            layout2.setVisibility(View.VISIBLE);
        }
    }
      
    public void setText(String title,String content,String btnOkText,String btnCancelText,View.OnClickListener listener){
        Button btnOk = (Button)findViewById(R.id.btn_dialog_ok);
        Button btnCancel = (Button)findViewById(R.id.btn_dialog_cancel);
        btnOk.setText(btnOkText);
        btnCancel.setText(btnCancelText);
        btnCancel.setOnClickListener(listener);
        btnOk.setOnClickListener(listener);
        TextView txtTitle = (TextView)findViewById(R.id.txt_dialog_title);
        txtTitle.setText(title);
        TextView txtContent = (TextView)findViewById(R.id.txt_dialog_content);
        txtContent.setText(content);
        setImgCloseListener();
    }
    
    public String getInputText(){
        EditText edit = (EditText)findViewById(R.id.etxt_dialog_input);
        if(edit!=null)
            return edit.getText().toString();
        return null;
    }
      
    public void setText(String title,String content,String btnText,View.OnClickListener listener){
        Button btnBack = (Button)findViewById(R.id.btn_dialog_back);
        btnBack.setText(btnText);
        btnBack.setOnClickListener(listener);
        TextView txtTitle = (TextView)findViewById(R.id.txt_dialog_title);
        txtTitle.setText(title);
        TextView txtContent = (TextView)findViewById(R.id.txt_dialog_content);
        txtContent.setText(content);
        setImgCloseListener();
    }
    
    private void setImgCloseListener(){
        ImageView imgViewClose = (ImageView)findViewById(R.id.imgview_dialog_close);
        imgViewClose.setOnClickListener(new View.OnClickListener() {
            
            public void onClick(View v) {
                // TODO Auto-generated method stub
                DialogEx.this.dismiss();
            }
        });
    }
    
}
